﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Serialization;
using System.IO;
using umbraco.IO;

namespace GrailTechnology.AutoTags.DataType
{
    [Serializable]
    public class Config
    {
        public static string pluginPath = "/plugins/OpenCalaisAutotag";

        public bool GenerateTagsAutomatically { get; set; }
        public bool SelectTagsAutomatically { get; set; }
        public bool AllowManualTags { get; set; }
        public bool AllowTagSuggestion { get; set; }

        public bool ShowHelp { get; set; }

		public string TagGroup { get; set; }

        public string OpenCalaisApiKey { get; set; }
        
        public string ProxyUsername { get; set; }
        public string ProxyPassword { get; set; }
        public string ProxyDomain { get; set; }

        static Config instance = null;



        private Config()
        {
        }

        public void Write()
        {
            XmlSerializer s = new XmlSerializer(typeof(Config));
            string file = IOHelper.MapPath("~/config/OpenCalaisAutotag/autotags.config");
            StringWriter sw = new StringWriter();
            s.Serialize(sw, this);

            File.WriteAllText(file, sw.ToString());

        }

        public static Config Instance
        {
            get
            {
                if (instance == null) {
                    XmlSerializer s = new XmlSerializer(typeof(Config));
                    String conf = File.ReadAllText(IOHelper.MapPath("~/config/OpenCalaisAutotag/autotags.config"));
                    instance = (Config)s.Deserialize(new StringReader(conf));
                }

                return instance;
            }
        }

    }
}